package com.qf.controller;

import com.qf.pojo.Product;
import com.qf.service.ProductService;
import com.qf.service.impl.ProductServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends BaseServlet {
    public void index(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        //调用商品业务接口获取最新商品和热门商品
        //System.out.println("子类的index方法执行了....");
        //获取到数据,请求转发到/jsp/index.jsp
        ProductService productService  = new ProductServiceImpl() ;
        List<Product> newProducts = productService.getNewProducts() ;
        List<Product> hotProdcuts = productService.getHotProdcuts();
        if(newProducts !=null && hotProdcuts !=null){
            //存储在request域中
            request.setAttribute("newProducts",newProducts);
            request.setAttribute("hotProdcuts",hotProdcuts) ;
        }

        request.getRequestDispatcher("/jsp/index.jsp").forward(request,response);
    }
}
